﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Web;

namespace GoogleQuery
{
    public class GoogleWeb
    {
        protected HtmlAgilityPack.HtmlDocument doc;

        public GoogleWeb()
        {
            doc = new HtmlAgilityPack.HtmlDocument();
        }

        protected byte[] GetWebRequest(string url)
        {
            HttpWebRequest wr = WebRequest.Create(url) as HttpWebRequest;
            wr.Method = "GET";
            wr.Timeout = 60000;
            wr.AllowAutoRedirect = true;
            wr.Accept = "text/html, application/xhtml+xml, */*";
            wr.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)";

            HttpWebResponse resp = wr.GetResponse() as HttpWebResponse;

            List<byte> bytes = new List<byte>();
            byte[] b = new byte[65535];
            using (Stream s = resp.GetResponseStream())
            {
                int cnt = 0;
                do
                {
                    cnt = s.Read(b, 0, b.Length);
                    for (int loop = 0; loop < cnt; loop++)
                        bytes.Add(b[loop]);
                }
                while (cnt > 0);
            }
            resp.Close();
            return bytes.ToArray();
        }
    }
}
